package com.zlj.accountant.db.dao;

import com.zlj.accountant.db.entity.TAccount;
import com.zlj.accountant.db.entity.TAccountBank;
import com.zlj.accountant.publish.BalanceType;

public class UpdateAccountBalanceSql{
	
	static final String TABLE = "%TABLE%";
	
	static final String FIELD = "%FIELD%";
	
	static final String sql =
			new StringBuilder()
				.append("update ")
				.append(TABLE)
				.append(" set ")
				.append(FIELD)
				.append(" = ").append(FIELD).append("+?")
				.append(" where ").append(TAccountBank.Field_Id).append("=?").toString();
	
	public static String getSql(String table,BalanceType type){
		return sql.replace(TABLE,table).replaceAll(FIELD, BalanceType.Income == type ? TAccount.Field_Income : TAccount.Field_Outgo);
	}
	
}
